﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Cangku.Model;

namespace Cangku.DAL
{
    public class ShopInfo
    {
        /// <summary>
        /// 通过商品编号获取商品id
        /// </summary>
        /// <param name="shopId"></param>
        /// <returns></returns>
        public static int GetIdByShopId(string shopId)
        {
            using (DemoDBEntities db=new DemoDBEntities())
            {
                var shop = db.tb_shopInfo.FirstOrDefault(s=>s.shopId==shopId);
                if (shop!=null)
                {
                    return shop.id;
                }
                else
                {
                    return -1;
                }
            }
        }
        /// <summary>
        /// 新增一条出库记录
        /// </summary>
        /// <param name="sto"></param>
        /// <returns></returns>
        public static bool AddStorage(tb_storage sto)
        {
            using (DemoDBEntities db=new DemoDBEntities())
            {
                db.tb_storage.Add(sto);
                return db.SaveChanges() > 0;
            }
        }
        /// <summary>
        /// 查询所有出库信息
        /// </summary>
        /// <returns></returns>
        public static List<tb_storage> GetAllStorage()
        {
            using (DemoDBEntities db=new DemoDBEntities())
            {
                var list = db.tb_storage.Include("tb_shopInfo").ToList();
                return list;
            }
        }
    }
}